{% extends "base.html" %}

{% block title %}v2ray管理器{% endblock %}

{% block css %}
    <link rel="stylesheet" href="/static/css/json-formatter.min.css">
    <style>
        .panel_from {
            margin: 2%;
        }
    </style>
{% endblock %}

{% block heard %}v2ray管理器{% endblock %}

{% block js %}
    <script src="/static/js/json-formatter.umd.min.js"></script>
    <script src="/static/js/utils.js"></script>
{% endblock %}

{% block content %}
<!--  内容页面  -->
    <div class="layui-tab layui-tab-card" style="margin: 2%;">
      <ul class="layui-tab-title">
          {% for item in utils_list %}
            <li {% if loop.index == 1 %}class="layui-this" {% endif %}>{{ item.name }}</li>
          {% endfor %}
      </ul>

      <div class="layui-tab-content">
          {% for item in utils_list %}
              <div {% if loop.index == 1 %} class="layui-tab-item layui-show" {% else %} class="layui-tab-item" {% endif %}>
                <form class="layui-form layui-form-pane panel_from">
                  <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                      <textarea placeholder="请输入内容" name="content" class="layui-textarea"></textarea>
                    </div>
                  </div>
                  <div class="layui-form-item">
                      {% for btn in item.btnList %}
                        <button class="layui-btn" lay-submit lay-filter="{{ btn.data }}">{{ btn.name }}</button>
                      {% endfor %}
                  </div>
                </form>
            </div>
          {% endfor %}

      </div>
    </div>

    <!-- 全局按钮  -->
    <div class="layui-panel" style="margin:2%;">
        <form class="layui-form layui-form-pane panel_from">
            <div class="layui-form-item">
            {%for item in gold_list %}
                <button class="layui-btn" lay-submit lay-filter="{{ item.data }}">{{ item.name }}</button>
            {% endfor %}
            </div>
        </form>
    </div>

    <!--  内容页面  -->
    <div class="layui-panel" style="margin:2%;">
      <div id="content" style="padding: 32px;"></div>
    </div>
{% endblock %}

{% block js_content %}
    <script>
        layui.define(function(exports){
            // 输出接口
            exports('common', {
                run_start: function () {
                    let form = layui.form;
                    // 按钮列表
                    let btn_str_list = JSON.parse('{{ btn_list | tojson | safe}}');
                    // 全局按钮
                    let gold_btn_list = JSON.parse('{{ gold_btn_list | tojson | safe}}');
                    // 数组列表
                    let btn_arrays = btn_str_list.concat(gold_btn_list);
                    btn_arrays.forEach((item) => {
                        form.on('submit(' + item + ')', function(data){
                            // 非全局按钮不检测参数
                            if(!gold_btn_list.includes(item)){
                                let content = data.field.content;
                                if (!content || content.length <= 0) {
                                    layer.alert("请输入内容后操作" + content, {title: '提示', time: 3000});
                                    return false;
                                }
                            }
                            functions[item](data.field);
                            return false;
                        });
                    });
                }
            });
        });
    </script>
{% endblock %}